package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TmcPartyBuilding;
import com.ruoyi.system.service.ITmcPartyBuildingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区党建Controller
 * 
 * @author ruoyi
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/system/building")
public class TmcPartyBuildingController extends BaseController
{
    @Autowired
    private ITmcPartyBuildingService tmcPartyBuildingService;

    /**
     * 查询社区党建列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TmcPartyBuilding tmcPartyBuilding)
    {
        startPage();
        List<TmcPartyBuilding> list = tmcPartyBuildingService.selectTmcPartyBuildingList(tmcPartyBuilding);
        return getDataTable(list);
    }

    /**
     * 小程序查询社区党建列表
     */
    @GetMapping("/queryPartyBuilding")
    public TableDataInfo queryPartyBuilding()
    {
        List<TmcPartyBuilding> list = tmcPartyBuildingService.queryPartyBuilding();
        return getDataTable(list);
    }

    /**
     * 导出社区党建列表
     */
    @Log(title = "社区党建", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TmcPartyBuilding tmcPartyBuilding)
    {
        List<TmcPartyBuilding> list = tmcPartyBuildingService.selectTmcPartyBuildingList(tmcPartyBuilding);
        ExcelUtil<TmcPartyBuilding> util = new ExcelUtil<TmcPartyBuilding>(TmcPartyBuilding.class);
        return util.exportExcel(list, "building");
    }

    /**
     * 获取社区党建详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:building:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tmcPartyBuildingService.selectTmcPartyBuildingById(id));
    }

    /**
     * 新增社区党建
     */
    // @PreAuthorize("@ss.hasPermi('system:building:add')")
    @Log(title = "社区党建", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TmcPartyBuilding tmcPartyBuilding)
    {
        return toAjax(tmcPartyBuildingService.insertTmcPartyBuilding(tmcPartyBuilding));
    }

    /**
     * 修改社区党建
     */
    //@PreAuthorize("@ss.hasPermi('system:building:edit')")
    @Log(title = "社区党建", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmcPartyBuilding tmcPartyBuilding)
    {
        return toAjax(tmcPartyBuildingService.updateTmcPartyBuilding(tmcPartyBuilding));
    }

    /**
     * 删除社区党建
     */
    //@PreAuthorize("@ss.hasPermi('system:building:remove')")
    @Log(title = "社区党建", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tmcPartyBuildingService.deleteTmcPartyBuildingByIds(ids));
    }
}
